var _sint=null;
var _int=null;
(function() {
	var page       = pf.newPage('status', true);
	var $el        = null;
	var $lcover    = null;
	var $gcover    = null;
	var $videoZone = null;

	var loopTimer = null;
	/**
	 * 初始化时调用
	 */
	page.onCreate = function() {
		$el        = page.$el;
		// $lcover = page.$lcover = $el.find('.thirty_show');
		// $lcover    = page.$lcover = $gcover = page.$gcover = $el.find('.go_image');
		$lcover = page.$lcover = $el.find('.go_image');
		$videoZone = page.$videoZone = $el.find('.video_status');

		$el.on('click', function() {
			startLoop();
		});

		$el.on("click",".status_center_left",function(){
			kpi.store('entrance', 'click');
			$(document).click();
			pf.goPage('show', {showID: 'wdy'});
			pcc2.isHand = true;
			return false;
		});
		// $el.on('click','.vide_id',function(){
			// page.showQRCode();
		// });
	};

	page.showQRCode = function() {
		$lcover.fadeIn();
		$videoZone.addClass('blur');
	};
	page.hideQRCode = function() {
		$lcover.fadeOut();
		$videoZone.removeClass('blur');
	};
	var fei=true;
	var startLoop = function() {
		closeLoop();
		var show = function() {
			page.showQRCode();
			loopTimer = window.setTimeout(hide, 10000);
			if (fei) {
				if ($('.video_status').find('.logo_show')) {
					$el.find(".video_status").find('.logo_show').empty();
					$('.video_status').find('.logo_show').append('<audio id="auto_s" autoplay="autoplay" src="./wav/Master_Sport_MD.wav">您的浏览器不支持 audio 标签。</audio>');
					fei=false;
				};
			};
			// loopTimer = window.setTimeout(hide, 1000);
		};
		var hide = function() {
			page.hideQRCode();
			if ($('.video_status').find('.logo_show')) {
				  _int=self.setInterval(function(){
						var myaudio=document.getElementById("auto_s");
						if (!myaudio) {
							$('.video_status').find('.logo_show').empty();
							fei=true;
							clearInterval(_int);
						}else{
							myaudio.volume=myaudio.volume-0.01;
							console.log(myaudio.volume)
							if (myaudio.volume<0.01) {
								myaudio.volume=0.0;
								$('.video_status').find('.logo_show').empty();
								fei=true;
								clearInterval(_int);
							};
						}
				},20)
			};
		};
		show();
	};
	var closeLoop = function() {
		clearTimeout(loopTimer);
		loopTimer = null;
	};
	/**
	 * 页面显示时自动调用
	 */
	var eventTester = function(){
		// var Media = document.getElementById("vide_id"); 
	 //  	 Media.addEventListener("ended",function(){
	 //   },false);
	}
	page.onShow = function() {
		clearInterval(_int);
		clearInterval(_sint);
		$el.find(".video_status").empty();
		$el.find(".video_status").fadeIn();
		// $el.find(".page_door").fadeOut();
		$el.find(".video_status").append('<div class="logo_show"><audio id="auto_s" autoplay="autoplay" src="./wav/Master_Sport_MD.wav">您的浏览器不支持 audio 标签。</audio></div>');
		// $el.show();
		eventTester();
		// pcc2.light('off');
		
		pcc2.isHand = false;
		pcc2.$cover.hide();
		startLoop();
		if (localStorage.camera=="开") {
				$("#webcam").addClass('kai');
		};
		// page.hideQRCode();
		page.$lcover.hide();
		$videoZone.removeClass('blur');
	};

	/**
	 * 页面隐藏时调用
	 */
	page.onHide = function() {
		// $el.hide();
		$el.find(".video_status").fadeOut();
			if ($('.video_status').find('.logo_show')) {
				  _sint=self.setInterval(function(){
						var myaudio=document.getElementById("auto_s");
						if (!myaudio) {
								$('.video_status').empty();
								fei=true;
								clearInterval(_sint);
						}else{
							myaudio.volume=myaudio.volume-0.01;
							console.log(myaudio.volume);
							if (myaudio.volume<0.01) {
								myaudio.volume=0;
								$('.video_status').empty();
								fei=true;
								clearInterval(_sint);
							};
						}
				},20);
		// page.hideQRCode();
		};
		// $el.find(".video_status").empty();

		closeLoop();
	};

})();